<h5><i class="icon-th-list"></i> Status CIS</h5>

<div id="accordion2" class="accordion">
    <?php
    // busca das áreas do ciss
    $sql5 = "SELECT * FROM cissarea WHERE status='1' AND cis_are_id2='0' ORDER BY cis_are_id,cis_are_id2";
    $res5 = sql($sql5);
    $c=0;
    while($linha5=mysql_fetch_array($res5)){
        
        // pegar as subáreas 
        $sql_area = "SELECT * FROM cissarea WHERE status='1' AND cis_are_id2='{$linha5['cis_are_id']}'";
        $res_area = sql($sql_area);
        $d=0;
        while($linha_area=mysql_fetch_array($res_area)){
            
            if ($d == 0){ 
                $list_area = $linha_area['cis_are_id'];
            } else {
                $list_area .= ",'{$linha_area['cis_are_id']}'"; 
            }
           $d++; 
           
        }

    ?>
    <div class="accordion-group">
        
        
        <?php
        
        if ($list_area != ""){
        
            $sql_ciss = "SELECT ciss.sta_id,status.sta_cor 
            FROM ciss 
            INNER JOIN status ON status.sta_id=ciss.sta_id 
            WHERE ciss.status='1' AND ciss.cis_are_id IN ($list_area)";
            $res_ciss = sql($sql_ciss);
            $num_cor = mysql_num_rows($res_ciss);
            
            $i = 0;
            while($linha_ciss = mysql_fetch_array($res_ciss)){
                
                if ($linha_ciss['sta_id'] == 1){ $idcor1++; }
                if ($linha_ciss['sta_id'] == 2){ $idcor2++; }
                if ($linha_ciss['sta_id'] == 3){ $idcor3++; }
                if ($linha_ciss['sta_id'] == 4){ $idcor4++; }

                if ($i == 0) { 

                    $aux = $linha_ciss['sta_id'];
                    $cor = $linha_ciss['sta_cor'];

                } else {

                    if ($linha_ciss['sta_id'] < 4){

                        $aux = $linha_ciss['sta_id'];
                        $cor = $linha_ciss['sta_cor'];    

                    } elseif ($linha_ciss['sta_id'] == 4) {
                        
                        if ($idcor4 == $num_cor) {
                            
                            $aux = $linha_ciss['sta_id'];
                            $cor = $linha_ciss['sta_cor'];
                            
                        } else {
                            
                            $aux = 3;
                            $cor = "FBFF7A";
                            
                        }

                    }

                }

                $i++;

            }
            
            unset($idcor1);
            unset($idcor2);
            unset($idcor3);
            unset($idcor4);

        }
           
        ?>
        
        <div class="accordion-heading">
            
            <a class="accordion-toggle" href="#<?=$c;?>" data-parent="#accordion2" data-toggle="collapse"><span style='width: 20px;height: 20px; background-color:#<?=$cor;?>;'>&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;<strong><?=$linha5['cis_are_nome'];?></strong><span class="icon-chevron-down pull-right"></span></a>
        
        </div>
        <div id="<?=$c;?>" class="accordion-body collapse">
            
            <div class="accordion-inner">
                
                <table class="table table-striped table-bordered table-hover">

                    <tr>
                        <td width="100"><strong><?=$t_setor;?></strong></td>
                        <td><strong>Status</strong></th>
                    </tr>

                    <?php
                    
                    if ($_GET['cis_are_id'] != "") { 
                        $onde = " AND ciss.cis_are_id='{$_GET['cis_are_id']}'"; 
                    } else {  
                        $onde = " AND ciss.cis_are_id IN ($list_area)";
                    }
                    $sql6 = "SELECT DISTINCT(ciss.cis_are_id) AS cis_are_id,
                    ciss.cis_id,
                    ciss.cis_ini,
                    ciss.cis_fim,
                    ciss.cis_horaini,
                    ciss.cis_horafim,
                    ciss.cis_msg,
                    ciss.cis_url,
                    status.sta_nome,
                    status.sta_cor,
                    cissarea.cis_are_nome
                    FROM ciss,cissarea,status
                    WHERE ciss.status='1' AND cissarea.cis_are_id=ciss.cis_are_id AND status.sta_id=ciss.sta_id $onde
                    ORDER BY ciss.cis_id DESC";
                    $res6 = sql($sql6);
                    $i=0;
                    while($linha6 = mysql_fetch_array($res6)) {

                        if (isset($area_id)){

                            if (in_array($linha6['cis_are_id'],$area_id)){ $aux = 0; } else { $aux = 1; $area_id[] = $linha6['cis_are_id']; }

                        } else {

                            $aux = 1; 
                            $area_id[] = $linha6['cis_are_id'];

                        }

                        if ($aux == 1){

                            $cis_are_nome   = $linha6['cis_are_nome'];
                            $cis_are_id     = $linha6['cis_are_id'];
                            $cis_id         = $linha6['cis_id'];

                    ?>

                    <tr>
                        <td><?=$linha6['cis_are_nome'];?></td>
                        <td>
                            <span style='width: 25px;height: 25px; background-color:#<?=$linha6['sta_cor'];?>;font-size:20px;'>&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;<span style="color:<?=$linha6['sta_cor'];?>;font-weight: bold"><?=$linha6['sta_nome'];?></span><a href="#detalheciss<?=$cis_id;?>" class="btn pull-right" data-toggle="modal" title="<?=$t_hist;?>"><?=$t_deta;?></a>
                            <?php 
                            if ($linha6['cis_url']!= ""){ echo "<p><i class='icon-file' title='Realize o Download do Documento'></i> <a href='service/{$linha6['cis_url']}' target='_blank'>".str_replace('.jpg','',str_replace('arquivo/','',$linha6['cis_url']))."</a></p>"; }
                            include "mod/detalheciss/index.php"; 
                            ?>
                        </td>
                    </tr>

                    <?
                            $i++;
                        }
                        unset($aux);
                    } 
                    ?>
                </table>

            </div>
        </div>
        
    </div>
    <?php 
    $c++;
    unset($ponto);
    unset($cor);
    unset($aviso);
    } 
    ?>
</div>